package cn.wolfcode._IOday01_.synthesizeWork01;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class InputDemo00 {
    public static void main(String[] args) throws IOException {
        File file = new File("calcCharNum.txt");
        FileInputStream intputStream = new FileInputStream(file);
        byte[] b = new byte[100];
        int off = 0 ;
        int len ;
        String s = null;
        while((len = intputStream.read(b)) != -1){
            s = new String(b, off, len);
            System.out.println("s = " + s);
        }
        TreeMap<Character,Integer> map = new TreeMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (map.containsKey(c)){
               int g = map.get(c);
               g++;
               map.put(c,g);
            }else {
                map.put(c,1);
            }
        }
        System.out.println(map);
        String str = "";
        Set<Map.Entry<Character,Integer>> set = map.entrySet();
        for (Map.Entry<Character,Integer> sets : set){
            Character key = sets.getKey();
            Integer value = sets.getValue();
            str += key+"("+value+"),";
        }
        System.out.println("str = " + str);
        String substring = str.substring(0, str.length() - 1);
        System.out.println("substring = " + substring);
    }
}
